<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import=" com.demo.entity.Products"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我要下单</title>
<script type="text/javascript">     
     function check(form) {
        var regu = /^[1-9]\d*$/;
        if(form.quantity.value == ''){
            alert("数量值不能为空 ! ");
            form.quantity.focus();
            return false;
        }
        if(!regu.test(form.quantity.value)){
            alert("必须输入整数 ! ");
            form.quantity.focus();
            return false;           
        }
        if(parseInt(form.pnum.value) < parseInt(form.quantity.value)){
            alert("抱歉，商品数量有限(购买量不能大于库存量) ! ");
            return false;    
        }
        if(form.rename.value == ''){
        	alert("收件人不能为空 ! ");
            return false;    
        }
        if(form.rephone.value.length < 7){
            alert("收件号码有误，请检查 ! ");
            return false;    
        }
        if(form.readdress.value == ''){
            alert("收件地址不能为空 ! ");
            return false;    
        }
    }
</script>
</head>
<body>
    <form action="/WebStoreSSM/controller/orderInfo" method="post">
        <fieldset>
            <legend style="color: #00f"> <h3>我要下单  . . . </h3></legend>
            <%
            Products products = (Products)session.getAttribute("products");
            %>
            <input type="hidden" name="pid" value="<%=products.getProduct_id()%>"/>
            <input type="hidden" name="pname" value="<%=products.getName()%>"/>
            <input type="hidden" name="price" value="<%=products.getPrice()%>"/>
            <input type="hidden" name="pnum" id="pnum" value="<%=products.getPnum()%>"/>
            <table>
                <tr><th>商品名：</th><th><%=products.getName()%></th></tr>
                <tr><th>价格：</th><th><%=products.getPrice()%></th></tr>
                <tr><th>库存量：</th><th><%=products.getPnum()%></th></tr>
                <tr><th>购买量：</th><th><input type="text" name="quantity" id="quantity" /></th></tr>
                <tr><th>收件人：</th><th><input type="text" name="rename" id="rename" /></th></tr>
                <tr><th>收件号码：</th><th><input type="text" name="rephone" id="rephone" /></th></tr>
                <tr><th>收件地址：</th><th><textarea rows="5" cols="30" name="readdress" id="readdress"></textarea></th></tr>
                <tr><th colspan="2" align="center"><input type="submit" value="下单" onclick="return check(this.form)"/></th></tr>
                <tr><th colspan="6" align="right"><a href="/WebStoreSSM/views/product_list.jsp">查看商品列表</a></th>
                        <th><a href="/WebStoreSSM/controller/order_list_action">订单查询</a></th></tr>
            </table>
        </fieldset>
    </form>
</body>
</html>